Repository navigation
Encode error objects into json before logging them - #668
jadhavgaurav wants to merge 2 commits into
Conversation
Serpentian
left a comment
There was a problem hiding this comment.
Congratulations on your first contribution! Great patch, let's work a little bit more with it)
d82be73 to
a239eed
Compare
|
Thanks for the review. I amended the commit and force-pushed (a239eed). Per point:
Full test-run suite passes locally except |
Serpentian
left a comment
There was a problem hiding this comment.
We're moving fast! Great!
a239eed to
8f37849
Compare
|
Thanks, all points addressed. Force-pushed two commits (8f37849 on top of 991623d), per point:
Local run on Tarantool 3.8.1: luatest and test-run suites pass, luacheck has only the two existing |
8f37849 to
bd328e2
Compare
|
Rebased onto master (conflicts in vshard/storage/init.lua and vshard/storage/schema.lua, where master dropped the pcall calls my logging change touched), no functional change; ready for another look. New head: bd328e2 |
Serpentian
left a comment
There was a problem hiding this comment.
Even though we dropped the support for Tarantool 1.10 (where the problem with crutchy table logging was present), I think the patch is still useful to make error logging more safe and consistent. These look like the last comments from me! Thank you for fixing all the nits!
VShard errors are stringified with json.encode() as __tostring. It raises on the values it can't encode: a function or a table key, which is neither a number nor a string. An error can carry such values, for example in a payload of a custom box.error. Errors are stringified when they are logged, so the failed encoding breaks the logging itself and hides the original problem. Return the error message if the error can't be encoded. Also use one metatable for all the error kinds instead of the three equal ones. Part of tarantool#651 NO_DOC=bugfix Signed-off-by: Gaurav Jadhav <gaurav.vjadhav01@gmail.com>
bd328e2 to
ca1a619
Compare
|
Done. The test now runs on |
ca1a619 to
2c51863
Compare
|
Thanks, both done. The cleanup is now plain statements at the end of On moving One caveat: on Tarantool 3.8.1 the new test also passes with only the ratelimiter change reverted, because this version already honours |
VShard error objects are plain Lua tables with a __tostring metamethod. Several log messages print them with the '%s' format, which does not always call __tostring, so the error is not logged readably. The recovery service was already fixed in c347440. Do the same for the rest of the log messages, which print an error: call tostring() on the error passed through lerror.make(). lerror.make() also converts strings and box errors, so they are logged as json too instead of just the message. Closes tarantool#651 Closes tarantool#624 NO_DOC=bugfix Signed-off-by: Gaurav Jadhav <gaurav.vjadhav01@gmail.com>
2c51863 to
bf9f98b
Compare
Serpentian
left a comment
There was a problem hiding this comment.
Sorry, but I think that adding the tostring is the wrong road here. We started the review process, when Tarantool 1.10 was still supported and the issue really existed. Now we support only Tarantool >= 2.11, which properly handles the tostring and it became excessive. I propose to have the following patchset:
- error: make the error stringification safe -- as it's now
- Revert "storage: fix error logging in the recovery service"
- error: convert all errors for consistent logging --
lerror.make
| limiter:log_warn(err, service:set_status_error( | ||
| 'Error during discovery %s, retry will be done later: %s', | ||
| rs_id, err)) | ||
| rs_id, tostring(lerror.make(err)))) |
There was a problem hiding this comment.
Tarantool 1.10 is not supported by VShard anymore, and the minimum supported version (2.11) already has no problems with calling the tostring by itself. So this new tostring is excessive. Let's drop it from the patch.
The lerror.make can remain. The motivation is consistent logging of errors: otherwise Tarantool's error's are logged as message only, but vshard ones: with code, fields, message and so on. The commit msg should be updated.
| log.info(start_format, type) | ||
| limiter:log_error(err, | ||
| 'Error during recovery of bucket %s on replicaset %s: %s', | ||
| bucket_id, peer_id, json_encode(err)) |
There was a problem hiding this comment.
This json_encode is excessive too now, let's make the commit, which reverts the c347440 and describe the reason for that revert in the commit msg: the minimum supported version already properly calls the tostring of the tables. This revert commit can also close the issues (since old tarantool, which caused them are not supported anymore) and be marked as part of #673
Closes #651. Also closes #624, which reports the same symptom for the
replication_status ... is unknownmessage.Problem
VShard error objects are plain Lua tables carrying
__tostring = json.encode(vshard/error.lua). Tarantool'slogmodule formats its arguments throughstring.format(), and only recent LuaJIT versions call__tostringfor%s. On the older Tarantool versions vshard still supports, an error object is printed as a bare table address:The recovery service was already fixed in c347440 ("Let's fix only recovery for now"). This does the rest.
Change
json_encode(err)at every remaining log/set_status_errorsite that prints an error object:vshard/storage/init.lua: recovery, garbage collector, master_sync and rebalancer services, plus the rebalancer worker and route-applying messages.vshard/router/init.lua: both discovery failure messages.vshard/replicaset.lua: initial-handshake close,replica_callexception, replica backoff, master locate/search, failover ping and step, worker service failure, and thereplication_statusupdate fromreplica_failover_ping(that last one is Malformed replication status log message #624).vshard/util.lua: the reloadable fiber loop failure message.Two notes on scope:
pcall()and the surrounding code already normalised it withlerror.make(), thelerror.make()call is kept and wrapped. Inreplica_call()the existinglerror.make(err)is hoisted above the log so the logged object and the returned object are the same one.pcall()over plain box API calls (droppingon_replacetriggers,_schemaupgrade/downgrade invshard/storage/schema.lua) are deliberately left alone: those errors arebox.errorcdata, which never prints as a table address.json.encodeis safe for every shape that reaches these sites: an error table, abox.errorcdata (serialised to its message) and a plain string all encode without raising.Testing
No new test, matching
NO_TEST=minoron c347440. The bug is invisible on any Tarantool wherestring.format('%s', obj)honours__tostring, which is the case for every version I can run locally — the pre-fix code already emits the same json there.test/storage-luatest/storage_1_1_1_test.luaalready asserts json content ('Error during downloading rebalancer states:.*"replicaset_id":"%s"') for one of these messages; this change makes that hold on the old versions too.Full suite run on Tarantool 3.8.1 (macOS): 93 passed, 1 skipped, 5 disabled, 1 failed. The single failure is
upgrade/upgrade.test.lua, which fails identically on unmodifiedmasterhere with a test-run harness error (RuntimeError: dictionary changed size during iterationinpreprocessor.py), so it is unrelated to this change. I could not test against an old Tarantool where the bug actually reproduces, so the behaviour on those versions is reasoned about rather than observed.